// 导入静态路由
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: constantRoutes // 所有人默认拥有静态路由
}
const mutations = {
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  // 筛选权限路由
  filterRoutes(context, menus) {
    const routes = []
    menus.forEach(key => {
      // 得到一个数组 有可能 有元素 也有可能是空数组
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })
    context.commit('setRoutes', routes) // 将动态路由提交给 mutations
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}

